package org.jeecg.modules.flower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.utils.UuidUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.flower.entity.*;
import org.jeecg.modules.flower.mapper.FlowerTagPrintMapper;
import org.jeecg.modules.flower.service.*;
import org.jeecg.modules.flower.vo.TFlowerTagInMain2Page;
import org.jeecg.modules.flowerutil.PeriodUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * @Description: 标签打印表-新版
 * @Author: jeecg-boot
 * @Date: 2022-10-13
 * @Version: V1.0
 */
@Service
@Slf4j
public class FlowerTagPrintServiceImpl extends ServiceImpl<FlowerTagPrintMapper, FlowerTagPrint> implements IFlowerTagPrintService {

    @Autowired
    private IFlowerVarietyService flowerVarietyService;
    @Autowired
    private ITFlowerTagInMain2Service flowerTagInMain2Service;
    @Autowired
    private ITFlowerTagIn2Service flowerTagIn2Service;
    @Autowired
    private IFlowerOutorderPrtService flowerOutorderPrtService;
    @Autowired
    private IFlowerOutorderService flowerOutorderService;
    @Autowired
    private IFlowerOutorderinfoService flowerOutorderinfoService;

    @Autowired
    private IFlowerOutorderPreService flowerOutorderPreService;
    @Autowired
    IFlowerOutorderPreinfoService flowerOutorderPreinfoService;

    @Autowired
    private IFlowerOutlogService flowerOutlogService;
//    @Autowired
//    private IFlowerTagPrintService flowerTagPrintService;
    @Autowired
    private IFlowerTagInfoService flowerTagInfoService;


    /**
     * 扫码入库
     *
     * @return java.lang.Integer
     * @descriptionauthor
     * @author gf
     * 2022-10-13 9:20
     * [id]
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer ScanInTagInfo(List<String> ids, String storehouse,String productionId) {
        Integer i = 0;
        LoginUser sysUser = new LoginUser();
        try {
            sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();

        } catch (Exception e) {
            sysUser.setRealname("自动扫码");
        }
        TFlowerTagInMain2 flowerTagInMain2 = new TFlowerTagInMain2();
        String mainid = UuidUtils.getUUID();
        flowerTagInMain2.setId(mainid);
        flowerTagInMain2.setStorehouse(storehouse);
        flowerTagInMain2.setProductionId(productionId);
        flowerTagInMain2.setPeriod(PeriodUtils.getDefaultPeriod()); //当前账期
        flowerTagInMain2.setInType("扫码入库");

        List<TFlowerTagIn2> tFlowerTagIn2List = new ArrayList<>();
        List<String> TagPrintList = new ArrayList<>();

        for (String id : ids) {
            if (StringUtils.isBlank(id)) {
//                throw new RuntimeException("扫码失败，id为空");
                log.info(id + "扫码失败，id为空！");
                continue;
            }
            FlowerTagPrint flowerTagPrint = this.getById(id);
            if (flowerTagPrint == null) {
//                throw new RuntimeException("入库失败！未找到id：" + id + "的数据！");
                log.info(id + "标签不存在！");
                continue;
            }
            if (flowerTagPrint.getState() == 1) {
//                throw new RuntimeException(id + "已经入库过了！");
                log.info(id + "已经入库过了！");
                continue;
            }
            QueryWrapper<TFlowerTagInMain2> taginQuery2 =new QueryWrapper<>();
            taginQuery2.eq("state",0);
            taginQuery2.inSql("id","select mainid from t_flower_tag_in where tagprint_id ='"+id+"'" );
            long count = flowerTagInMain2Service.count(taginQuery2);
            if (  count >0 ) {
//                throw new RuntimeException(id + "已经入库过了！");
                log.info(id + "已经入库过了！");
                continue;
            }
           /* LambdaQueryWrapper<TFlowerTagIn2> taginQuery = new LambdaQueryWrapper<>();
            taginQuery.eq(TFlowerTagIn2::getTagprintId, id);
            List<TFlowerTagIn2> list1 = flowerTagIn2Service.list(taginQuery);
            if (list1.size() > 0) {
//                throw new RuntimeException(id + "已经入库过了！");
                log.info(id + "已经入库过了！");
                continue;
            }*/

            LambdaQueryWrapper<FlowerVariety> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(FlowerVariety::getName, flowerTagPrint.getVariety());
            queryWrapper.eq(FlowerVariety::getPackingSpecifications, flowerTagPrint.getPackingSpecifications());
            queryWrapper.eq(FlowerVariety::getFlowerPoleLength, flowerTagPrint.getFlowerPoleLength());
            queryWrapper.eq(FlowerVariety::getClasses, flowerTagPrint.getClasses());
            List<FlowerVariety> list = flowerVarietyService.list(queryWrapper);
            if (list.size() != 1) {
                throw new RuntimeException(flowerTagPrint.getVariety() + "查找编码时存在重复数据，入库失败！请联系管理员添加品种" + id);
            }
            FlowerVariety variety = list.get(0);

            //新增入库主子表--同时插入到台账数据
//            TFlowerTagInMain2 flowerTagInMain2 = new TFlowerTagInMain2();
            flowerTagInMain2.setSourceBase(flowerTagPrint.getSourceBase());
            flowerTagInMain2.setSourceGreenhouse(flowerTagPrint.getSourceGreenhouse());
            flowerTagInMain2.setSortTime(flowerTagPrint.getSortTime());

            TFlowerTagIn2 flowerTagIn2 = new TFlowerTagIn2();
            flowerTagIn2.setInType("扫码入库");
            flowerTagIn2.setStorehouse(storehouse);
            flowerTagIn2.setProductionId(productionId);
            flowerTagIn2.setSourceBase(flowerTagPrint.getSourceBase());
            flowerTagIn2.setSourceGreenhouse(flowerTagPrint.getSourceGreenhouse());
            flowerTagIn2.setVariety(variety.getName());
            flowerTagIn2.setVarietyCode(variety.getCode());
            flowerTagIn2.setPackingSpecifications(variety.getPackingSpecifications());
            flowerTagIn2.setFlowerPoleLength(variety.getFlowerPoleLength());
            flowerTagIn2.setClasses(variety.getClasses());
            flowerTagIn2.setTagNum(new BigDecimal(1));
            flowerTagIn2.setSortTime(flowerTagPrint.getSortTime());//分拣日期
            flowerTagIn2.setTagprintId(id);
//            flowerTagIn2.setSortTime(new Date()); //扫码入库时间

            tFlowerTagIn2List.add(flowerTagIn2);

            TagPrintList.add(id);
            //更新标签表状态和入库人
//            FlowerTagPrint flowerTagPrintNew = new FlowerTagPrint();
//            flowerTagPrintNew.setId(id);
//            flowerTagPrintNew.setInTime(new Date());
//            flowerTagPrintNew.setInPeople(sysUser.getRealname());
//            flowerTagPrintNew.setState(1);
//            this.updateById(flowerTagPrintNew);
            i++;
        }
        if (tFlowerTagIn2List.size() > 0) {
            flowerTagInMain2Service.saveMain(flowerTagInMain2, tFlowerTagIn2List);
            flowerTagInMain2Service.sure(flowerTagInMain2.getId());//自动调用确认入库
        }
        if (TagPrintList.size() > 0) {
            //更新标签表状态和入库人
            UpdateWrapper<FlowerTagPrint> updateWrapper =new UpdateWrapper<>();
            updateWrapper.in("id",TagPrintList);
            updateWrapper.set("in_time",new Date());
            updateWrapper.set("in_people", sysUser.getRealname());
            updateWrapper.set("state",1);
            this.update( updateWrapper);
        }

        return i;
    }

    /**
     * PDA扫码出库-新版-扫码出库--将扫码的ids存起来
     *
     * @return java.lang.String
     * @descriptionauthor
     * @author gf
     * 2022-11-7 8:58
     * [ids, orderNo]
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public String ScanOutPDAByIds(String ids, String orderNo) {
        String rest = "扫码失败";
        if (StringUtils.isBlank(orderNo)) {
            throw new RuntimeException("请先扫码出库单！");
        }
        if (StringUtils.isBlank(ids)) {
            throw new RuntimeException("先扫码一个产品标签！");
        }
        // 同订单的的重复扫码，  // 不同订单好重复扫码
        LambdaQueryWrapper<FlowerOutorderPrt> flowerOutorderPrtLambdaQueryWrapper = new LambdaQueryWrapper<>();
        flowerOutorderPrtLambdaQueryWrapper.eq(FlowerOutorderPrt::getPrintId, ids);
        FlowerOutorderPrt flowerOuterprt = flowerOutorderPrtService.getOne(flowerOutorderPrtLambdaQueryWrapper);
        if (flowerOuterprt != null && flowerOuterprt.getState() == 1) {
            //已经出库
            throw new RuntimeException(ids + "已经出库过了，出库单：【" + flowerOuterprt.getOrderNo()+"】");
        } else if (flowerOuterprt != null && flowerOuterprt.getState() == 0 && orderNo.equals(flowerOuterprt.getOrderNo())) {
            return "已经扫码过了！";
        } else if (flowerOuterprt != null && flowerOuterprt.getState() == 0 && !orderNo.equals(flowerOuterprt.getOrderNo())) {
            throw new RuntimeException(ids + "已被出库单：【" + flowerOuterprt.getOrderNo() + "】扫码过了！");
        }

        FlowerOutorderPrt flowerOutorderPrt = new FlowerOutorderPrt();
        flowerOutorderPrt.setPrintId(ids);
        flowerOutorderPrt.setOrderNo(orderNo);
        String orderid = "";
        if (orderNo.indexOf("YCK") >= 0) {
            //预出库
            LambdaQueryWrapper<FlowerOutorderPre> flowerOutorderPreLambdaQueryWrapper = new LambdaQueryWrapper<>();
            flowerOutorderPreLambdaQueryWrapper.eq(FlowerOutorderPre::getOrderNo, orderNo);
            FlowerOutorderPre flowerPre = flowerOutorderPreService.getOne(flowerOutorderPreLambdaQueryWrapper);
            orderid = flowerPre.getId();

            // 查找是否在台账中数据是否符合订单中条件。
            //判断扫码出库的id 是否和该出库单的子表相符合，判断数量
            isInOutOrderPreList(  ids,  orderid, orderNo);
        } else if (orderNo.indexOf("CK") >= 0) {
            //出库申请
            LambdaQueryWrapper<FlowerOutorder> flowerOutorderLambdaQueryWrapper = new LambdaQueryWrapper<>();
            flowerOutorderLambdaQueryWrapper.eq(FlowerOutorder::getOrderNo, orderNo);
            FlowerOutorder flowerOutorder = flowerOutorderService.getOne(flowerOutorderLambdaQueryWrapper);
            orderid = flowerOutorder.getId();
            // 查找是否在台账中数据是否符合订单中条件。
            //判断扫码出库的id 是否和该出库单的子表相符合，判断数量
            isInOutOrderList(  ids,  orderid, orderNo);
        }
        flowerOutorderPrt.setOrderId(orderid);
        flowerOutorderPrt.setState(0);
        boolean save = flowerOutorderPrtService.save(flowerOutorderPrt);
        if (save) {
            rest = "扫码成功";
        }
        return rest;
    }

    /**
     * PDA扫码出库-新版-扫码出库--确认出库
     *
     * @return java.lang.String
     * @descriptionauthor
     * @author gf
     * 2022-11-7 8:58
     * [orderNo]
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public String ScanOutPDASure(String orderNo) throws IOException {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        String rest = "确认出库失败！";
        int re = 0;
        BigDecimal totalNumber = BigDecimal.ZERO ;
        String orderid ="";
        //1、核对出库数量是否和出库单一致
        List<FlowerOutorderHZ> flowerOutorderHZS = flowerOutorderPrtService.getlistByOrderNo("", orderNo);
        BigDecimal count =  BigDecimal.ZERO ;
        Map<String,FlowerOutorderHZ> map =new HashMap<>();
        for(FlowerOutorderHZ flowerOutorderHZ: flowerOutorderHZS){
            BigDecimal number = flowerOutorderHZ.getNumber();
            count = count .add(  number) ;
            //扫码信息
            map.put(flowerOutorderHZ.getStorehouse()+"_"+flowerOutorderHZ.getVarietyCode(), flowerOutorderHZ);
        }
        if (orderNo.indexOf("YCK") >= 0) {
            //预出库
            LambdaQueryWrapper<FlowerOutorderPre> flowerOutorderPreLambdaQueryWrapper = new LambdaQueryWrapper<>();
            flowerOutorderPreLambdaQueryWrapper.eq(FlowerOutorderPre::getOrderNo, orderNo);
            FlowerOutorderPre flowerPre = flowerOutorderPreService.getOne(flowerOutorderPreLambdaQueryWrapper);
            orderid = flowerPre.getId();
            List<FlowerOutorderPreinfo> flowerOutorderPreinfos = flowerOutorderPreinfoService.selectByMainId(orderid);
            for(FlowerOutorderPreinfo flowerOutorderPreinfo: flowerOutorderPreinfos){
                //出库单子表数量
                BigDecimal number = flowerOutorderPreinfo.getNumber();
                totalNumber = totalNumber .add( number)  ;

                FlowerOutorderHZ flowerOutorderHZ22 =  map.get(flowerOutorderPreinfo.getStorehouse()+"_"+ flowerOutorderPreinfo.getVarietyCode());
                if(flowerOutorderHZ22==null){
                    throw new RuntimeException(flowerOutorderPreinfo.getVariety()+ flowerOutorderPreinfo.getFlowerPoleLength()+"扫码数量(0)和出库数量("+number+")不一致！ ");
                }
                BigDecimal number1 = flowerOutorderHZ22.getNumber();
                if (number.compareTo(number1) != 0) {
                    throw new RuntimeException(flowerOutorderPreinfo.getVariety() + flowerOutorderPreinfo.getFlowerPoleLength() + "扫码数量(" + number1 + ")和出库数量(" + number + ")不一致！ ");
                }
                //预出库单子表id存在map里面。
                flowerOutorderHZ22.setOutOrderinfoID(flowerOutorderPreinfo.getId() );
                map.put(flowerOutorderPreinfo.getStorehouse()+"_"+ flowerOutorderPreinfo.getVarietyCode(),flowerOutorderHZ22);
            }
            //3、出库调用--针对实物---扫已扎花、出的就是这扎花
            re += flowerTagInfoService.outPreTagInfoPDA(orderid,flowerPre.getChannel(),flowerPre.getAccountno(),map,flowerPre.getStockInTime());
            //4、 -1改为0---修改预出库单状态

            flowerPre.setStockOutUser(sysUser.getRealname());//出库人
            flowerPre.setStockInTime(new Date());
            flowerOutorderPreService.saveTagPreBach(flowerPre);

        } else if (orderNo.indexOf("CH-CK") >= 0) {
            //出库申请
            LambdaQueryWrapper<FlowerOutorder> flowerOutorderLambdaQueryWrapper = new LambdaQueryWrapper<>();
            flowerOutorderLambdaQueryWrapper.eq(FlowerOutorder::getOrderNo, orderNo);
            FlowerOutorder flowerOutorder = flowerOutorderService.getOne(flowerOutorderLambdaQueryWrapper);
            if(flowerOutorder.getState()!=2){
                throw new RuntimeException("请先进行【运管审核】后才能出库！");
            }
            orderid = flowerOutorder.getId();
            List<FlowerOutorderinfo> flowerOutorderPreinfos = flowerOutorderinfoService.selectByMainId(orderid);
            for(FlowerOutorderinfo flowerOutorderinfo: flowerOutorderPreinfos){
                BigDecimal number = flowerOutorderinfo.getNumber();
                totalNumber = totalNumber .add(number)  ;

                FlowerOutorderHZ flowerOutorderHZ22 =  map.get(flowerOutorderinfo.getStorehouse()+"_"+ flowerOutorderinfo.getVarietyCode());
                if(flowerOutorderHZ22==null){
                    throw new RuntimeException(flowerOutorderinfo.getVariety()+ flowerOutorderinfo.getFlowerPoleLength()+"扫码数量(0)和出库数量("+number+")不一致！ ");
                }
                BigDecimal number1 = flowerOutorderHZ22.getNumber();
                if(number1.compareTo( number)!=0){
                    throw new RuntimeException(flowerOutorderinfo.getVariety()+ flowerOutorderinfo.getFlowerPoleLength()+"扫码数量("+number1+")和出库数量("+number+")不一致！ ");
                }
                //出库单子表id存在map里面。
                flowerOutorderHZ22.setOutOrderinfoID(flowerOutorderinfo.getId() );
                map.put(flowerOutorderinfo.getStorehouse()+"_"+ flowerOutorderinfo.getVarietyCode(),flowerOutorderHZ22);
            }
            re += flowerOutorderService.sureOutDo(orderid);
        }else{
            throw new RuntimeException( "无效出库单编号！"+ orderNo);
        }
        if(totalNumber.compareTo(count ) !=0 ){
            throw new RuntimeException("出库总数量和扫码总数量不相等，不能出库！扫码总数："+count+",出库单出库总数："+totalNumber);
        }
        //2、再次判断是否是属于该出库单的出库花，是否是否正确。 暂时不用。


        //5、修改暂存扫码表的状态。
        UpdateWrapper<FlowerOutorderPrt> prtUpdateWrapper =new UpdateWrapper<>();
        prtUpdateWrapper.eq("order_no",orderNo);
        prtUpdateWrapper.set("state",1); //0草稿，1已出库
        flowerOutorderPrtService.update(prtUpdateWrapper);
        rest = "确认出库成功"  ;
        return rest;
    }


    /**
     * 删除关联的扫码标签关联单。
     * @descriptionauthor
     * @author gf
     * 2022-11-10 8:53
     * [orderNo]
     * @return java.lang.String
     */
    @Override
    public String ScanOutPDADeleteByOrderno(String orderNo) {
        QueryWrapper<FlowerOutorderPrt> flowerOutorderPrtQueryWrapper = new QueryWrapper<>();
        flowerOutorderPrtQueryWrapper.eq("order_no", orderNo);
        List<FlowerOutorderPrt> list = flowerOutorderPrtService.list(flowerOutorderPrtQueryWrapper);
        for(FlowerOutorderPrt flowerOutorderPrt : list){
            if(flowerOutorderPrt.getState()==1){
                throw new  RuntimeException("已经确认出库，不能删除");
            }
        }
        boolean remove = flowerOutorderPrtService.remove(flowerOutorderPrtQueryWrapper);
        if(remove) {
            return "删除成功";
        }else{
            return "删除失败";
        }
    }

    //判断扫码出库的id 是否和该出库单的子表相符合,数量是否已足够=====出库单申请
    private void isInOutOrderList(String ids, String orderid, String orderNo) {
        LambdaQueryWrapper<TFlowerTagIn2> taginQuery = new LambdaQueryWrapper<>();
        taginQuery.eq( TFlowerTagIn2::getTagprintId,ids);
        List<TFlowerTagIn2> list = flowerTagIn2Service.list(taginQuery);
        if(list.size()>0){
            TFlowerTagIn2 flowerTagIn2 = list.get(0);
            String variety = flowerTagIn2.getVariety();
            String varietyCode = flowerTagIn2.getVarietyCode();
            String flowerPoleLength = flowerTagIn2.getFlowerPoleLength();
            String packingSpecifications = flowerTagIn2.getPackingSpecifications();
            String storehouse = flowerTagIn2.getStorehouse();

            LambdaQueryWrapper<FlowerOutorderinfo> orderinfoQuery = new LambdaQueryWrapper<>();
            orderinfoQuery.eq(FlowerOutorderinfo::getOrderId,orderid);
            orderinfoQuery.eq(FlowerOutorderinfo::getVarietyCode,varietyCode);
            orderinfoQuery.eq(FlowerOutorderinfo::getFlowerPoleLength,flowerPoleLength);
            orderinfoQuery.eq(FlowerOutorderinfo::getPackingSpecifications,packingSpecifications);
            orderinfoQuery.eq(FlowerOutorderinfo::getStorehouse,storehouse);
            List<FlowerOutorderinfo> Outorderinfolist1 = flowerOutorderinfoService.list(orderinfoQuery);
            if(Outorderinfolist1.size()==0){
                throw new RuntimeException("该产品不属于这个出库单，标签id："+ids+"；出库单：【"+orderNo+"】");
            }
            if(Outorderinfolist1.size()>1){
                log.error(" PDA扫码出库-------判断扫码出库的id 是否和该出库单的子表相符合,子表符合条件数量大于1"+list.size()
                + "。出库单id："+ orderid+ ".出库单单号：【"+ orderNo+ "】标签id："+ ids);
            }
            FlowerOutorderinfo flowerOutorderinfo = Outorderinfolist1.get(0);
            BigDecimal number = flowerOutorderinfo.getNumber();
            if(number==null || "".equals(number)){
                number =  BigDecimal.ZERO;
            }
            BigDecimal num =   number ;
            //判断数量
            List<FlowerOutorderHZ> flowerOutorderHZS = flowerOutorderPrtService.getlistByOrderNo(ids,orderNo);
            if(flowerOutorderHZS.size()>0) {
                FlowerOutorderHZ flowerOutorderHZ = flowerOutorderHZS.get(0);
                BigDecimal number1 = flowerOutorderHZ.getNumber();
                if(number1==null || "".equals(number1)){
                    number1 = BigDecimal.ZERO ;
                }
                BigDecimal num2 =  number1 ;
                if(num2.equals(num) ){
                    throw new RuntimeException(variety+"("+flowerPoleLength+")已经满足出库单出库数量"+num2+"。无需再出库该产品！");
                }else if(num2.compareTo(num) > 0){
                    throw new RuntimeException(variety+"("+flowerPoleLength+")已经超过出库单出库数量"+num2);
                }
            }
        }else{
            throw new RuntimeException("未找到该入库信息，标签id："+ids);
        }
    }
    //判断扫码出库的id 是否和该出库单的子表相符合,数量是否已足够=====预出库申请
    private void isInOutOrderPreList(String ids, String orderid, String orderNo) {
        LambdaQueryWrapper<TFlowerTagIn2> taginQuery = new LambdaQueryWrapper<>();
        taginQuery.eq( TFlowerTagIn2::getTagprintId,ids);
        List<TFlowerTagIn2> list = flowerTagIn2Service.list(taginQuery);
        if(list.size()>0){
            TFlowerTagIn2 flowerTagIn2 = list.get(0);
            String variety = flowerTagIn2.getVariety();
            String varietyCode = flowerTagIn2.getVarietyCode();
            String flowerPoleLength = flowerTagIn2.getFlowerPoleLength();
            String packingSpecifications = flowerTagIn2.getPackingSpecifications();
            String storehouse = flowerTagIn2.getStorehouse();

            LambdaQueryWrapper<FlowerOutorderPreinfo> orderinfoQuery = new LambdaQueryWrapper<>();
            orderinfoQuery.eq(FlowerOutorderPreinfo::getOrderId,orderid);
            orderinfoQuery.eq(FlowerOutorderPreinfo::getVarietyCode,varietyCode);
            orderinfoQuery.eq(FlowerOutorderPreinfo::getFlowerPoleLength,flowerPoleLength);
            orderinfoQuery.eq(FlowerOutorderPreinfo::getPackingSpecifications,packingSpecifications);
            orderinfoQuery.eq(FlowerOutorderPreinfo::getStorehouse,storehouse);
            List<FlowerOutorderPreinfo> Outorderinfolist1 = flowerOutorderPreinfoService.list(orderinfoQuery);
            if(list.size()==0|| Outorderinfolist1.size()==0){
                throw new RuntimeException("该产品不属于这个预出库申请单，标签id："+ids+"；预出库申请单：【"+orderNo+"】");
            }
            if(list.size()>1){
                log.error(" PDA扫码出库预出库申请-------判断扫码出库的id 是否和该预出库申请单的子表相符合,子表符合条件数量大于1"+list.size()
                + "。预出库申请单id："+ orderid+ ".预出库申请单号："+ orderNo+ ".标签id："+ ids);
            }
            FlowerOutorderPreinfo flowerOutorderPreinfo = Outorderinfolist1.get(0);
            BigDecimal number = flowerOutorderPreinfo.getNumber();
            BigDecimal num =   number ;
            //判断数量
            List<FlowerOutorderHZ> flowerOutorderHZS = flowerOutorderPrtService.getlistByOrderNo(ids,orderNo);
            if(flowerOutorderHZS.size()>0) {
                FlowerOutorderHZ flowerOutorderHZ1 = flowerOutorderHZS.get(0);
                BigDecimal number1 = flowerOutorderHZ1.getNumber();
                BigDecimal num2 =   number1 ;
                if(num2.compareTo(num) >= 0){
                    throw new RuntimeException(variety+"("+flowerPoleLength+")已经满足出库单出库数量"+num2);
                }
            }
        }else{
            throw new RuntimeException("未找到该入库信息，标签id："+ids);
        }
    }


}
